Python console/pt-br

Introdução

The Python console is a panel that's part of the FreeCAD user interface. It runs an instance of the Python interpreter which can be used to control FreeCAD processes, and create and modify objects and their properties.

It can be made visible/hidden through the View → Panels → Python console drop-down menu.

The Python console in FreeCAD has basic syntax highlighting, able to differentiate with various styles and colors, comments, strings, numeric values, built in functions, printed text output, and delimiters like parentheses and commas. These properties of the console can be configured in the Preferences editor.

The Python console showing messages when FreeCAD has just started.

Scripting

For absolute beginners, see: Introduction to Python, and Python scripting tutorial.

See also: FreeCAD scripting basics, and Scripted objects.

The Python console can perform basic code completion when a dot is written after an object; it will show public methods and attributes (variables) of the current object (class), for example, obj.

The console is also able to show the documentation string of a particular function when the opening parenthesis is written, for example, function(

Example Python code that produces objects in the 3D view.

The FreeCAD initialization scripts automatically load some modules, and define some aliases. Therefore, in the Python console these are available

App = FreeCAD
Gui = FreeCADGui

Therefore these are equal

App.newDocument()
FreeCAD.newDocument()

Note: these pre-loaded modules and aliases are only available from the Python console embedded inside the FreeCAD program. If you use FreeCAD as a library in an external program, you must remember to load the FreeCAD and FreeCADGui modules and define the necessary aliases if you wish.

Ações

Right click on the Python console shows some commands:

Notes